package de.lmu.ifi.pst.uwejsf.framework;

import java.util.List;
import java.util.Map;

public class PersistenceManagerQueryHandler implements QueryHandler {
	private String navigationNode;
	private Class<?> contentType;
	private String expression;

	public PersistenceManagerQueryHandler(String navigationNode,
			Class<?> contentType) {
		this.navigationNode = navigationNode;
		this.contentType = contentType;
	}

	@Override
	public List<?> executeQuery(Map<String, Object> parameters,
			ExpressionContextProvider contextProvider) {
		PersistenceManager pm = contextProvider.getPersistenceManager();
		String modelQName = pm.getModelQNameString(contentType
				.getCanonicalName());
		List<?> result = pm.query(modelQName, expression, navigationNode,
				parameters, contextProvider);
		return result;
	}

	@Override
	public String getExpression() {
		return expression;
	}

	@Override
	public void setExpression(String expression) {
		this.expression = expression;

	}

}
